<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      //[1,[2],[3,[4]],[5,[6,[7,[8,[9]]]]]]
      function getArrayDepth(arr) {
        let maxDepth = 1 //默认深度为1
        for (let item of arr) {
          if (Array.isArray(item)) {
            //计算出每一个数组里面的最大深度
            let depth = getArrayDepth(item) + 1
            //找到最深的那个，然后返回最后取最大值
            maxDepth = Math.max(depth, maxDepth)
          }
        }
        return maxDepth
      }
      console.log(getArrayDepth([1, [2], [3, [4]], [5, [6, [7, [8, [9]]]]]]))
    </script>
  </body>
</html>
